//
//  ByDocumentaryBombView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/23.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryBombView.h"
#import "ByDocumentaryChooseValue.h"

@implementation ByDocumentaryBombView

- (id)init{
    self = [super init];
    if (self) {
        [self initViews];
    }
    return self;
}

- (void)initViews{
    // 设置弹出方式和位置
    self.positionMode = ZKBombPositionModeBottom;
    self.popMode = ZKBombPopModeBottom;
    
    // 自定义视图
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 182)];
    contentView.backgroundColor = rgba(238, 238, 238, 1);
    self.contentView = contentView;
    
    
    UILabel *titleLabel1 = [[UILabel alloc] init];
    [self.contentView addSubview:titleLabel1];
    titleLabel1.textColor = BY_TEXT_COLOR;
    titleLabel1.font = FONT(14);
    titleLabel1.text = @"立即跟单";
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.centerX.equalTo(self.contentView).offset(0);
        make.size.mas_equalTo(CGSizeMake(80, 16));
    }];
    
    UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-15);
        make.top.mas_equalTo(self.contentView).offset(5);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    [deleteBtn setImage:[UIImage imageNamed:@"shanchu投注单"] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIView *bottomView = [[UIView alloc] init];
    [contentView addSubview:bottomView];
    bottomView.backgroundColor = [UIColor whiteColor];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentView).offset(0);
        make.right.equalTo(contentView).offset(0);
        make.bottom.equalTo(contentView).offset(0);
        make.top.equalTo(contentView).offset(34);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 70, 14)];
    [bottomView addSubview:titleLabel];
    titleLabel.textColor = BY_TEXT_COLOR;
    titleLabel.font = FONT(14);
    titleLabel.text = @"跟单倍数";
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [bottomView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView).offset(-13);
        make.centerY.equalTo(titleLabel.mas_centerY).offset(0);
        make.left.equalTo(titleLabel.mas_right).offset(10);
        make.height.mas_equalTo(@15);
    }];
    moneyLabel.textColor = BY_TEXT_COLOR;
    moneyLabel.font = FONT(14);
    moneyLabel.textAlignment = NSTextAlignmentRight;
    self.moneyLabel = moneyLabel;
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [bottomView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView).offset(0);
        make.bottom.equalTo(bottomView).offset(0);
        make.height.mas_equalTo(@50);
        make.width.mas_equalTo(@100);
    }];
    sureBtn.backgroundColor = BY_THEME_COLOR;
    [sureBtn setTitle:@"投注" forState:UIControlStateNormal];
    [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sureBtn.titleLabel.font = FONT(14);
    sureBtn.tag = 100;
    [sureBtn addTarget:self action:@selector(betAction:) forControlEvents:UIControlEventTouchUpInside];
    
    BySuperLottoAddMinusView *addMinusView = [[BySuperLottoAddMinusView alloc] init];
    [bottomView addSubview:addMinusView];
    [addMinusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView).offset(0);
        make.bottom.equalTo(bottomView).offset(0);
        make.size.mas_equalTo(CGSizeMake(150, 50));
    }];
    addMinusView.buyLabel.text = @"买";
    addMinusView.timesLabel.text = @"倍";
    addMinusView.countLabel.text = @"5";
    addMinusView.updateBlock = ^(){
        if (self.updateBlock) {
            self.updateBlock();
        }
    };
    self.addMinusView = addMinusView;
    
    UILabel *totalLabel = [[UILabel alloc] init];
    [bottomView addSubview:totalLabel];
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(sureBtn.mas_left).offset(-10);
        make.left.equalTo(addMinusView.mas_right).offset(10);
        make.centerY.mas_equalTo(sureBtn.mas_centerY).offset(0);
        make.height.mas_equalTo(@16);
    }];
    totalLabel.textAlignment = NSTextAlignmentCenter;
    totalLabel.font = FONT(15);
    totalLabel.textColor = BY_THEME_COLOR;
    self.totalLabel = totalLabel;
    
    ByDocumentaryChooseValue *chooseValue = [[ByDocumentaryChooseValue alloc] init];
    [bottomView addSubview:chooseValue];
    [chooseValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView).offset(0);
        make.right.equalTo(bottomView).offset(0);
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(18);
        make.height.mas_equalTo(@30);
    }];
    chooseValue.selectValueBlock = ^(NSInteger index){
        if (index == 0) {
            self.addMinusView.countLabel.text = @"5";
        }else if (index == 1){
            self.addMinusView.countLabel.text = @"10";
        }else if (index == 2){
            self.addMinusView.countLabel.text = @"20";
        }else if (index == 3){
            self.addMinusView.countLabel.text = @"50";
        }
        if (self.updateBlock) {
            self.updateBlock();
        }
    };

}

- (void)betAction:(UIButton *)btn{
    
    if (self.betBlock) {
        self.betBlock();
    }
    
}


- (void)deleteBtn:(UIButton *)btn{
    [self remove];
}

@end
